package com.geek.java.ch02;

public class Person {
    private String name;
    private int age;
    private boolean gender;  //性别  true男  false女
    private Person partner;

    //判断是否达到法定的结婚年龄  true代表达到法定结婚年龄，false代表未达到法定结婚年龄
    private boolean isAge(){
        if(this.gender&&this.age>=24 || !this.gender&&this.age>=22){
            return true;
        }
        return false;
    }

    public boolean marry(Person p){
        //1，同性；
        if(this.gender == p.gender){
            System.out.println("目前国内不支持办理，请前往自由美利坚办理！");
            return false;
        }
        //2，未达到结婚年龄，男<24，女<22；
        if(!this.isAge() || !p.isAge()){
            System.out.println("未成年牢底坐穿，成年也要等几年！");
            return false;
        }
        //3，某一方已婚
        if(this.partner!=null || p.partner!=null){
            System.out.println("已婚人士请离婚后再来！");
            return false;
        }

        //颁发结婚证
        this.partner = p;
        p.partner = this;
        System.out.println("恭喜结婚，百年好合");
        return true;
    }


    public Person() {
    }

    public Person(String name, int age, boolean gender, Person partner) {
        this.name = name;
        this.age = age;
        this.gender = gender;
        this.partner = partner;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public boolean isGender() {
        return gender;
    }

    public void setGender(boolean gender) {
        this.gender = gender;
    }

    public Person getPartner() {
        return partner;
    }

    public void setPartner(Person partner) {
        this.partner = partner;
    }

    public String toString() {
        return "Person{name = " + name + ", age = " + age + ", gender = " + gender + ", partner = " + partner + "}";
    }
}
